number = input("Введите четырехзначное число:")
if len(number) == 4 and number.isdigit():
    number = int(number)
    largest_prime = 0
    for i in range(4, 0, -1):
        sub_number = int(str(number)[:i])
        is_prime = True
        if sub_number > 1:
            for j in range(2, int(sub_number**0.5) + 1):
                if sub_number % j == 0:
                    is_prime = False
                    break
            if is_prime:
                largest_prime = sub_number
                break
    print(largest_prime)
else:
    print(0)
